package ar.edu.unlu.sistemas.ws.business;

import java.io.Serializable;
import java.net.InetSocketAddress;
import java.util.StringTokenizer;

import javax.xml.bind.annotation.XmlType;

@XmlType
public class QueryResultVO implements Serializable {
	
	/**
	 * 
	 */
	private static final long serialVersionUID = -1010896848821215113L;
	private String file;
	private String address;
	private Integer port;
	private Float rating;
	private String path;
	
	public QueryResultVO() {
		
	};
	
	public QueryResultVO(String docName, Float value) {
		this.setDocName(docName);
		this.setValue(value);
	}
	
	public QueryResultVO(InetSocketAddress address, String docName, Float value) {
		this.setAddress(address.getAddress().getHostAddress());
		this.setPort(address.getPort());
		this.setDocName(docName);
		this.setValue(value);
	}
	
	public QueryResultVO(String address, int port, String docName, Float value) {
		this.setAddress(address);
		this.setPort(port);
		this.setDocName(docName);
		this.setValue(value);
	}
	
	public QueryResultVO(String address, String docName, Float value) {
		if (address!=null && !"".equals(address)  ) {
			StringTokenizer st = new StringTokenizer(address,":");
			this.setAddress(st.nextToken());
			this.setPort(Integer.parseInt(st.nextToken()));
		}
		this.setDocName(docName);
		this.setValue(value);
	}
	
	public String getAddress() {
		return address;
	}

	public void setAddress(String address) {
		this.address = address;
	}
	
	public Integer getPort() {
		return port;
	}

	public void setPort(Integer port) {
		this.port = port;
	}

	public String getDocName() {
		return file;
	}
	public void setDocName(String docName) {
		this.file = docName;
	}
	public Float getValue() {
		return rating;
	}
	public void setValue(Float value) {
		this.rating = value;
	}
	public String getPath() {
		return this.getDocName();
	}

	public void toString(StringBuffer sb) {
		sb.append("\n\t\t");
		sb.append(file);
		sb.append(" - ");
		sb.append(rating);
		sb.append(" ("+address+":"+port+")");
	}
	
}
